package bim.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import bim.dao.MessageDao;

@Service
public class MessageService {
    /**
     * Logger for this class
     */
    private static final Logger logger = LoggerFactory.getLogger(Service.class);

	@Autowired
    private MessageDao dao;
	
	@Autowired
	private UserService service;
	
   
    public MessageDao getDao() {
		return dao;
	}
    
//    public void sendMessageToTeacher(Topic topic) {
//        Message pm = new Message();
//        pm.setSender(service.getDao().findOne(1L));//管理员
////        pm.setReceiver(topic.getMaster());//导师
//        pm.setTitle("毕设课题提交通知");
////        pm.setContent("学生["+service.getDao().findOne(topic.getCreatorId()).getName()+"]的课题["
////                +topic.getName()+"]已提交，请您进行审阅处理。"); 
//        pm.setPosition(Position.INBOX.toString());
//        dao.save(pm);
//    }
    
//    public void sendMessageToStudent(Topic topic) {
//    	Message pm = new Message();
//        pm.setSender(service.getDao().findOne(1L));//管理员
////    	pm.setReceiver(topic.getFinisher());//学生
//    	pm.setTitle("毕设课题审阅结果通知");
////    	pm.setContent("您的课题["+topic.getName()+"]已批复，请访问“我的课题”页面查看结果。"); 
//    	pm.setPosition(Position.INBOX.toString());
//    	dao.save(pm);
//    }
    
//    public void sendReportMessageToTeacher(Report report) {
//    	Message pm = new Message();
//    	pm.setSender(service.getDao().findOne(1L));//管理员
//    	pm.setReceiver(report.getMaster());//导师
//    	pm.setTitle("开题报告提交通知");
//    	pm.setContent("学生["+service.getDao().findOne(report.getCreator().getId()).getName()+"]的开题报告["
//    			+report.getName()+"]已提交，请您进行审阅处理。"); 
//    	pm.setPosition(Position.INBOX.toString());
//    	dao.save(pm);
//    }
//    
//    public void sendReportMessageToStudent(Report report) {
//    	Message pm = new Message();
//    	pm.setSender(service.getDao().findOne(1L));//管理员
//    	pm.setReceiver(report.getCreator());//学生
//    	pm.setTitle("开题报告审阅结果通知");
//    	pm.setContent("您的开题报告["+report.getName()+"]已批复，请访问“报告”页面查看结果。"); 
//    	pm.setPosition(Position.INBOX.toString());
//    	dao.save(pm);
//    }
    
//    public void sendPaperMessageToTeacher(Paper report) {
//    	Message pm = new Message();
//    	pm.setSender(service.getDao().findOne(1L));//管理员
//    	pm.setReceiver(report.getMaster());//导师
//    	pm.setTitle("论文提交通知");
//    	pm.setContent("学生["+service.getDao().findOne(report.getCreator().getId()).getName()+"]的论文["
//    			+report.getName()+"]已提交，请您进行审阅处理。"); 
//    	pm.setPosition(Position.INBOX.toString());
//    	dao.save(pm);
//    }
    
//    public void sendPaperMessageToStudent(Paper report) {
//    	Message pm = new Message();
//    	pm.setSender(service.getDao().findOne(1L));//管理员
//    	pm.setReceiver(report.getCreator());//学生
//    	pm.setTitle("论文审阅结果通知");
//    	pm.setContent("您的论文["+report.getName()+"]已批复，请访问“论文”页面查看结果。"); 
//    	pm.setPosition(Position.INBOX.toString());
//    	dao.save(pm);
//    }
    
    /**
     * <p>Method ：deleteMyTopic
     * <p>Description : 只允许删除本人创建的课题
     * @param id
     * @param creatorAccountId 
     * @author  gulixing@msn.com
     * @version 1.0.0
     */
    public void deleteMyMessage(Long id,Long creatorAccountId){
    	if(!dao.findOne(id).getReceiver().getId().equals(creatorAccountId)){
			logger.error("用户id:[{}]尝试删除非本人收件箱内的消息",creatorAccountId);
			return;
		}
    	dao.deleteMessageById(id);
    }
}
